﻿@using Orchard.Utility.Extensions;
@using Orchard.ContentManagement;
@{
    var viewModel = Model.ViewModel as So.ContribReviews.UserReviewedItems.ViewModels.UserReviewedItemsViewModel;
    Style.Require("ContribStars").AtHead(); 
}

<b>@T("Reviews:")</b>
@if(viewModel.UserReviewItemViewModels.Count() > 0)
{
<ol>
    @foreach (var userReviewItem in viewModel.UserReviewItemViewModels)
    {
        <li>
            @{
        var roundedResult = Math.Round(userReviewItem.Review.Rating.CurrentVotingResult.Value * 2, MidpointRounding.AwayFromZero) / 2;
        var currentResultClass = string.Format("stars-value-{0}", Math.Floor(roundedResult));
        string title = userReviewItem.ContentItem.As<Orchard.Core.Routable.Models.RoutePart>().Title;
            }
            <h4>
                @Html.ItemDisplayLink(T("{0} {1}", title, userReviewItem.Review.CreatedUtc.ToString("dd MMMM yyyy")).Text, userReviewItem.ContentItem)
            </h4>
            <div class="stars-rating">
                <div class="stars-current-result @currentResultClass">
                    @if (roundedResult == .5)
                    {
                        <span class="star-0-5 a-half-star">@T(".").ToString()</span>
                        <span class="star-1 a-star a-half-star">@T("-").ToString()</span>
                    }
                    else
                    {
                        <span class="star-1 a-star">@(userReviewItem.Review.Rating.CurrentVotingResult.Value > 0 ? T("*").ToString() : T("-").ToString())</span>
                    }
                    @if (roundedResult == 1.5)
                    {
                        <span class="star-1-5 a-half-star">@T(".").ToString()</span>
                        <span class="star-2 a-star a-half-star">@T("-").ToString()</span>
                    }
                    else
                    {
                        <span class="star-2 a-star">@(userReviewItem.Review.Rating.CurrentVotingResult.Value > 1 ? T("*").ToString() : T("-").ToString())</span>
                    }
                    @if (roundedResult == 2.5)
                    {
                        <span class="star-2-5 a-half-star">@T(".").ToString()</span>
                        <span class="star-3 a-star a-half-star">@T("-").ToString()</span>
                    }
                    else
                    {
                        <span class="star-3 a-star">@(userReviewItem.Review.Rating.CurrentVotingResult.Value > 2 ? T("*").ToString() : T("-").ToString())</span>
                    }
                    @if (roundedResult == 3.5)
                    {
                        <span class="star-3-5 a-half-star">@T(".").ToString()</span>
                        <span class="star-4 a-star a-half-star">@T("-").ToString()</span>
                    }
                    else
                    {
                        <span class="star-4 a-star">@(userReviewItem.Review.Rating.CurrentVotingResult.Value > 3 ? T("*").ToString() : T("-").ToString())</span>
                    }
                    @if (roundedResult == 4.5)
                    {
                        <span class="star-4-5 a-half-star">@T(".").ToString()</span>
                        <span class="star-5 a-star a-half-star">@T("-").ToString()</span>
                    }
                    else
                    {
                        <span class="star-5 a-star">@(userReviewItem.Review.Rating.CurrentVotingResult.Value > 4 ? T("*").ToString() : T("-").ToString())</span>
                    }
                </div>
            </div>
            <div>
                <p class="review-item-text-expander">@userReviewItem.Review.Comment</p>
            </div>
        </li>
    }
</ol>
}
else
{
	<em>@T("No reviews written yet!")</em>
}
@using(Script.Foot())
{
<script type="text/javascript">
    //<![CDATA[
    $(function () {
        $('.review-item-text-expander').expander({
            preserveWords: true,
            slicePoint: 200,
            expandText: '@T("read more")',
            userCollapseText: '@T("read less")'
        });
    });
    //]]>
</script>
}